<template>
  <div style="margin-left:20px">
    <el-row>
      <el-col :span="12">
        <h3>一、输入框</h3>
        <div>
          <h4 class="h-Highlight">1.1、基础用法</h4>
          <el-input v-model="input" placeholder="请输入内容"></el-input>
        </div>

        <div style="margin-top:30px">
          <h4>1.2、禁用状态</h4>
          <el-input placeholder="请输入内容" v-model="input" :disabled="true">
          </el-input>
        </div>

        <div style="margin-top:30px">
          <h4 class="h-Highlight">1.3、可清空</h4>
          <el-input placeholder="请输入内容" v-model="input" clearable>
          </el-input>
        </div>

        <div style="margin-top:30px">
          <h4>1.4、密码框</h4>
          <el-input placeholder="请输入密码" v-model="input" show-password></el-input>

        </div>

        <div style="margin-top:30px">
          <h4 class="h-Highlight">1.5、带 icon 的输入框</h4>
          <div>
            属性方式：
            <el-input placeholder="请选择日期" suffix-icon="el-icon-date" v-model="input1">
            </el-input>
            <el-input placeholder="请输入内容" prefix-icon="el-icon-search" v-model="input2">
            </el-input>
          </div>
          <div>
            slot 方式：
            <el-input placeholder="请选择日期" v-model="input3">
              <i slot="suffix" class="el-input__icon el-icon-date"></i>
            </el-input>
            <el-input placeholder="请输入内容" v-model="input4">
              <i slot="prefix" class="el-input__icon el-icon-search"></i>
            </el-input>

          </div>

        </div>

        <div style="margin-top:30px">
          <h4>1.6、文本域</h4>
          <el-input type="textarea" :rows="5" placeholder="请输入内容" v-model="textarea">
          </el-input>

        </div>

        <div style="margin-top:30px">
          <h4 class="h-Highlight">1.7、可自适应文本高度的文本域</h4>
          <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" placeholder="请输入内容" v-model="textarea2">
          </el-input>
        </div>

        <div style="margin-top:30px">
          <h4>1.8、复合型输入框</h4>
          <el-input placeholder="请输入内容" v-model="input3" class="input-with-select">
            <el-select v-model="select" slot="prepend" placeholder="请选择">
              <el-option label="餐厅名" value="1"></el-option>
              <el-option label="订单号" value="2"></el-option>
              <el-option label="用户电话" value="3"></el-option>
            </el-select>
          </el-input>
        </div>

      </el-col>

      <el-col :span="1">
        <div class="line"></div>
      </el-col>

      <el-col :span="11">

        <div style="margin-top:30px">
          <h4>1.9、尺寸，可通过 size 属性指定输入框的尺寸，除了默认的大小外，还提供了 large、small 和 mini 三种尺寸。</h4>
          <el-input size="small" placeholder="请输入内容" suffix-icon="el-icon-date" v-model="input2">
          </el-input>
        </div>

        <div style="margin-top:30px">
          <h4 class="h-Highlight">1.10、带输入建议</h4>
          <el-autocomplete class="inline-input" v-model="state1" :fetch-suggestions="querySearch" placeholder="请输入内容" @select="handleSelect"></el-autocomplete>

        </div>

        <!-- <div style="margin-top:30px">
          <h4 class="h-Highlight">1.11、自定义模板</h4>
          <el-input placeholder="请输入内容" v-model="input">
            <template slot-scope="{ item }">
              <span style="color:red">{{ item }}</span>
            </template>
          </el-input>
        </div> -->

        <div style="margin-top:30px">
          <h4 class="h-Highlight">1.12、远程搜索</h4>
          <el-autocomplete v-model="state" :fetch-suggestions="querySearchAsync" placeholder="请输入内容" @select="handleSelect"></el-autocomplete>
        </div>

        <div style="margin-top:30px">
          <h4>1.13、输入长度限制</h4>
          <el-input type="textarea" placeholder="请输入内容" v-model="textarea" maxlength="30" show-word-limit>
          </el-input>

        </div>

      </el-col>

    </el-row>

  </div>
</template>

<script>

export default {
  data () {
    return {
      input: '片言',

      input1: '',
      input2: '',
      input3: '',
      input4: '',

      textarea: '',
      textarea2: '',
      select: '',

      //必须要有value 
      restaurants: [
        { "value": "三全鲜食（北新泾店）", "address": "长宁区新渔路144号" },
        { "value": "Hot honey 首尔炸鸡（仙霞路）", "address": "上海市长宁区淞虹路661号" },
        { "value": "新旺角茶餐厅", "address": "上海市普陀区真北路988号创邑金沙谷6号楼113" },
        { "value": "泷千家(天山西路店)", "address": "天山西路438号" },
        { "value": "胖仙女纸杯蛋糕（上海凌空店）", "address": "上海市长宁区金钟路968号1幢18号楼一层商铺18-101" },
        { "value": "贡茶", "address": "上海市长宁区金钟路633号" },
      ],
      state1: '',

      state: '',
      timeout: null,


      textarea: '',

    }
  },


  methods: {

    querySearch (queryString, cb) {
      var restaurants = this.restaurants;
      var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
      // 调用 callback 返回建议列表的数据
      console.log(results)
      cb(results);
    },


    createFilter (queryString) {
      return (restaurant) => {
        console.log(restaurant)
        return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
      };
    },

    handleSelect (item) {
      console.log(item);
    },


    querySearchAsync (queryString, cb) {
      var restaurants = this.restaurants;
      var results = queryString ? restaurants.filter(this.createStateFilter(queryString)) : restaurants;

      clearTimeout(this.timeout);
      this.timeout = setTimeout(() => {
        cb(results);
      }, 3000 * Math.random());
    },


    createStateFilter (queryString) {
      return (state) => {
        return (state.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
      };
    },

  }


}
</script>

<style scoped>
.line {
  border-left: 1px solid #9e9e9e;
  height: 1000px;
  margin-left: 8px;
}

.el-input {
  width: 200px;
}

.el-select .el-input {
  width: 150px;
}
.input-with-select .el-input-group__prepend {
  background-color: #fff;
}

.el-select {
  width: 120px;
}

.h-Highlight {
  color: red;
}
</style>